function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function formatDate() {
  Date.prototype.format = function (format) {
    var o = {
      "M+": this.getMonth() + 1, //month 
      "d+": this.getDate(), //day 
      "h+": this.getHours(), //hour 
      "m+": this.getMinutes(), //minute 
      "s+": this.getSeconds(), //second 
      "q+": Math.floor((this.getMonth() + 3) / 3), //quarter 
      "S": this.getMilliseconds() //millisecond 
    }

    if (/(y+)/.test(format)) {
      format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
      if (o.hasOwnProperty(k)) {
        if (new RegExp("(" + k + ")").test(format)) {
          format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
      }
    }
    return format;
  }

  Date.prototype.convert = function (dateStr) {
    if (dateStr) {
      // var date = eval('new Date(' + dateStr.replace(/\d+(?=-[^-]+$)/,
      //   function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
      var date = new Date(dateStr.replace(/\d+(?=-[^-]+$)/,
        function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g));
      var time = (Number(date));
      this.setTime(Number(time));
    }
  }
}

module.exports = {
  formatTime: formatTime,
  formatDate: formatDate
}
